import React, { Component } from 'react';

//组件更新时new props进行更新
class Demo extends Component{
  state={};
static getDerivedStateFromProps(props,state){
  console.log("1 getDerivedStateFromProps",props);
  return null;
};
shouldComponentUpdate(nextProps,nextState){
  console.log("2 shouldComponentUpdate");
return true;//组件更新
// return false;//组件不更新
};
  render(){
    console.log("3 执行render函数");
  return <h1>Demo组件{this.props.msg}</h1>
};
};
class App extends Component {   
  state={
    msg:"(*OO*)"
  };
  handleClick=(params) => {
    this.setState({
      msg:"^(*——(oo)——)^"
    });
  };
  render() {
    return (
      <div>
        <Demo msg={this.state.msg}> </Demo>
        <button onClick={this.handleClick}>变^(*——(oo)——)^</button>
      </div>
    );
  }
  getSnapshotBeforeUpdate(props,state){
    console.log("4 getSnapshotBeforeUpdate");
    return 100;
  };
  componentDidUpdate(props,state,snapshot){
    console.log("5 ComponentUpdate");
    console.log("来自getsnapshotBeforeUpdata得值:",snapshot);
  };
}

export default App;
